package cn.slipi.pan.web.controller;

import cn.slipi.pan.common.base.BaseController;
import cn.slipi.pan.common.response.ApiResult;
import cn.slipi.pan.web.dto.AuthDTO;
import cn.slipi.pan.web.entity.AuthEntity;
import cn.slipi.pan.web.service.AuthService;
import org.noear.solon.annotation.*;

@Controller
@Mapping("/auth")
public class AuthController extends BaseController {

    @Inject
    private AuthService authService;

    @Get
    @Mapping("/license")
    public ApiResult<?> license(@Param("license") String license) {
        AuthEntity authEntity = authService.getAuthByLicense(license);
        if (authEntity == null) {
            return fail();
        } else {
            AuthDTO authDTO = new AuthDTO()
                    .setToken(authEntity.getToken())
                    .setLoadUrl(authEntity.getLoadUrl())
                    .setVersion(authEntity.getVersion())
                    .setDownUrl(authEntity.getDownUrl());
            return success(authDTO);
        }
    }
}
